package com.vip.file.controller;

import com.github.pagehelper.PageInfo;
import com.vip.file.constant.UrlConstant;
import com.vip.file.model.dto.GetFileDto;
import com.vip.file.model.response.RestResponse;
import com.vip.file.model.response.RestResponses;
import com.vip.file.model.response.Result;
import com.vip.file.model.response.Results;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author ：xiongwei
 * @date ：Created in 2024/1/14 23:18
 */
@Slf4j
@RestController
@RequestMapping(UrlConstant.API + "/vue")
@RequiredArgsConstructor
public class VueTestController {

    /**
     * 获取文件列表
     *
     * @param pageNo   当前页
     * @param pageSize 分页大小
     * @return {@link RestResponse}<{@link List}<{@link GetFileDto}>>
     * @throws IOException ioexception
     */
    @GetMapping(value = "/list")
    public RestResponse<List<GetFileDto>> getFileList(@RequestParam Integer pageNo, @RequestParam Integer pageSize) throws IOException {

        List<GetFileDto> getFileDtoList = new ArrayList<>();

        for (int i = 0; i < 6; i++) {
            GetFileDto getFileDto = new GetFileDto();
            getFileDto.setFileName("test01"+i);
            getFileDto.setCreatedTime(new Date());
            getFileDto.setSuffix(i+"txt");
            getFileDto.setId(String.valueOf(i));
            getFileDtoList.add(getFileDto);
        }
        PageInfo<GetFileDto> pageInfo = new PageInfo<>(getFileDtoList);
        Result<List<GetFileDto>> result = Results.newSuccessResult(pageInfo.getList(), "查询成功", 20);
        return RestResponses.newResponseFromResult(result);
    }

}
